<template>
  <div>
    
    <el-table :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column prop="name" label="序号" >
          <template slot-scope="scope">{{scope.$index+1}}</template>
        </el-table-column>
      <el-table-column prop="type" label="类别" >
        <template slot-scope="scope">
          <span v-if="scope.row.type==3"> 视频</span>
          <span v-if="scope.row.type==4"> 问题</span>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="标签名" > </el-table-column>
      <el-table-column prop="color" label="色值" > </el-table-column>
      <el-table-column prop="publish_count" label="发布量" > </el-table-column>
      <el-table-column prop="page_view" label="点击量" > </el-table-column>      
      <el-table-column label="操作" width="220">
        <template slot-scope="scope">
          <div>
            <el-button class="addBtn" type="primary" v-if="scope.row.reflush_time == null" @click="putStick(scope.row.id)">置顶</el-button>
            <el-button class="addBtn" v-else @click="UpputStick(scope.row.id)">取消置顶</el-button>
            <el-button class="addBtn" type="success" @click="editDilog(scope.row)">编辑</el-button>
            <el-button class="addBtn" type="danger"  @click="deletaStick(scope.row.id)"> 删除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%" :before-close="handleClose" >
      <span>这是一段信息</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import Http from '@/Http/Http'
  export default {
    data() {
      return {
        userRole:JSON.parse(sessionStorage.getItem('userSolt')),
        dialogVisible:false,
        titleImgurl:'',
        total:0,
        currentPage4: 1,//分野
        pageIndex:1,
        pageSize:10,
        tableData:[]
      }
    },
    props:['navStatus'],
    created() {
      this.getlist()
    },
    methods: {
      getlist() {
        const obj ={
          pageIndex: this.pageIndex,
          pageSize:this.pageSize,
        };
        if(this.navStatus == 0){
          obj.type = 3
        } else {
          obj.type = 4
        }

        Http.getMarklist(obj)
        .then( res => {
          this.tableData = res.data.data.rows;
          this.total = res.data.data.total;
        })
        .catch( error => {
          
        })
      },
      editDilog(row) {
        this.$emit('editRow',row)
      },
       //分页
      handleSizeChange(val) {
        this.pageSize = val;
        this.getlist()
        
      },
      handleCurrentChange(val) {
        this.pageIndex = val;
        this.getlist()
        
      },


      //选择 推荐
      handleSelectionChange(val) {
        //this.$emit('checkFun',val)
      },
      
      //置顶
      putStick(val) {
       Http.stickMark(val)
       .then( res => {
          if( res.data.code == 200 ){
           this.$message.success('置顶成功')
           this.getlist()
          } else if(res.data.code == -1003) {
            this.$message.error(`请求失败原因：${res.data.message}`)
            setTimeout(()=>{
              this.$router.push('/')
            },2000)
          }
       })
       .catch( res => {
         this.$message.error('服务器请求失败')
       })
      },
      deletaStick(val) {
         this.$confirm('确认关闭？')
        .then(_ => {
          Http.deleteMark(val)
          .then( res => {
              if( res.data.code == 200 ){
              this.$message.success('删除成功')
              this.getlist()
              } else if(res.data.code == -1003) {
                this.$message.error(`请求失败原因：${res.data.message}`)
                setTimeout(()=>{
                  this.$router.push('/')
                },2000)
              }
          })
          .catch( res => {
            this.$message.error('服务器请求失败')
          })
        })
        .catch(_ => {});
        
      },
      //取消置顶
      UpputStick(val){
        Http.unStickMark(val)
       .then( res => {
          if( res.data.code == 200 ){
           this.$message.success('成功取消置顶')
           this.getlist()
          } else if(res.data.code == -1003) {
            this.$message.error(`请求失败原因：${res.data.message}`)
            setTimeout(()=>{
              this.$router.push('/')
            },2000)
          }
       })
       .catch( res => {
         this.$message.error('服务器请求失败')
       })
      },
      //审核
      passStick(val,i) {
        const arr = ['取消成功','审核成功','删除成功','取消成功']
        Http.postEditDynamic(val,i)
        .then( res => {
          if( res.data.code == 200 ){
            this.$message.success(arr[i])
            this.getlist()
          } else if(res.data.code == -1003) {
            this.$message.error(`请求失败原因：${res.data.message}`)
            setTimeout(()=>{
              this.$router.push('/')
            },2000)
          }
        })
        .catch( res => {
          this.$message.error('服务器请求失败')
        })
      },
     
      
      goEdit(){
        this.$router.push('/Home/editor')
      },
  
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      },
      //导出
      exportXlxs() {
      },
       //搜索
      sheachFun(val){
        
      },
     
    }
  }
</script>